var dataContro={
    contro:{},
    controStr:{},
    ksdata:[],
    jtksdata:[],
    mdcdata:[],
    drgdata:[],
    kmdat:[],
    userqy:[],
    userqyks:[],//{yqid:"",userks:[]}
    weiplan:3,//默认维方案切换
    //院区，MDC，DRG，病案科室，集团科室，集团科目（一级），集团科目（二级），病案科目（一级），病案科目（二级），
    // 主任医师，年度，月份，主治医师，科主任医师，住院医师
    arrs:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14],
    __KsLocalData:[],
    __JtKsLocalData:[],
    __weiplan:3,
    reportConfig:{
        options:[
            {name:"服务能力",cell:[1,2,3,4,5]},
            {name:"服务效率",cell:[6,7,8,9]},
            {name:"服务质量",cell:[10,11,12,13,14,15]},
            {name:"疗效分析",cell:[16,17,18,27,19,20,30]}
        ]
    },
    //contro={selRqkj:1,yqCon:1,ksCon:1,mdcCon:1,drgCon:1,kmCon:1,selCon:[],thbh:1}
    //日期类型，院区，科室，MDC，DRG，科目，
    // 维:{KS:科室,MDC:MDC,DRG:DRG,2:手术科室,1:非手术科室,km01:一级科目,km02:二级科目},thbh:同步环比
    // controStr={rqkjStr:"",srqStr:"",esqStr:"",yqStr:"",ksStr:"",kmStr:"",mdcStr:"",drgStr:"",weiStr:"",tbhbStr:""}
    init:function(contro,controStr,arrs){
        contro = contro||this.contro;
        this.contro = contro;
        controStr = controStr||this.controStr;
        this.controStr = controStr||this.controStr;
        var initThat = this;
        this.arrs=arrs||this.arrs;
        var postdata = {p_dm: "selectUserks"};
        this.initKjData(postdata,function(d){
            $.each(d.Table,function(index,item){
                if(item.yqid&&initThat.userqy.indexOf(item.yqid)<0){
                    initThat.userqy.push(item.yqid);
                }
                if(item.lx == 1){
                    initThat.userqyks.push({yqid:item.yqid,userks:[]});
                }else{
                    var iscks =false;
                    var thisksdata = {yqid:item.yqid,userks:[item.ksid]}
                    $.each(initThat.userqyks,function(ii,dd){
                        if(thisksdata.yqid==d.yqid){
                            thisksdata = dd;
                            thisksdata.ksdata.push(item.ksid);
                            iscks = true;
                            return true;
                        }
                    })
                    if(!iscks){
                        initThat.userqyks.push(thisksdata);
                    }
                }
            });
        });

        var str = "";
        str+='<li>';
        str+='<label>日期：</label>';
        if(contro.hasOwnProperty("selRqkj")&&contro.selRqkj) {
            str += '<select id="rqkj" onchange="dataContro.changeRqkj()" style="width: 40px;height: 24px;border-radius:2px;border: 1px solid #ddd">';
            str += '<option value="m">月</option>';
            //str += '<option value="j">季</option>';
            str += '<option value="y">年</option>';
        }
        str += '</select>'; str+='<input type="text" class="Wdate " id="srq" style="width: 80px;height: 24px;vertical-align: middle;margin-bottom: 3px;border-radius:2px;border: 1px solid #ddd"' +
            'onfocus="WdatePicker({el:\'srq\',startDate:\'%y\',dateFmt:\'yyyy-MM\',alwaysUseStartDate:true,maxDate:\'%y\'})">';
        str+='<input type="text" class="Wdate " id="erq" style="width: 80px;height: 24px;vertical-align: middle;margin-bottom: 3px;border-radius:2px;border: 1px solid #ddd"' +
            'onfocus="WdatePicker({el:\'erq\',startDate:\'%y\',dateFmt:\'yyyy-MM\',alwaysUseStartDate:true,maxDate:\'%y\'})">';

        str+='</li>';
        $("#topdiv").append(str);
        var date = new Date;
        var Predate=this.getPreMonth(date);
        var rqkjStr = controStr.hasOwnProperty("rqkjStr")&&controStr.rqkjStr;
        var srqStr=controStr.hasOwnProperty("srqStr")&&controStr.srqStr;
        var erqStr=controStr.hasOwnProperty("erqStr")&&controStr.erqStr;
        if(rqkjStr) {
            $("#rqkj").find("option[value='"+rqkjStr+"']").attr("selected",true);
        }
        if(rqkjStr=="y"){
            $("#srq").attr("onfocus","WdatePicker({el:'srq',startDate:'%y',dateFmt:'yyyy',alwaysUseStartDate:true,maxDate:'%y'})");
            $("#srq").val(srqStr||date.getFullYear());
            $("#erq").hide();
        }else{
            $("#srq").val(srqStr||Predate);
            $("#erq").val(erqStr||Predate);
        }


        if(contro.hasOwnProperty("yqCon")&&contro.yqCon){
            var str="";
            str+=' <li id="yqdiv">';
            str+='<label>院区</label>';
            str+='<select id="selyq"  onchange="dataContro.loadKsData()" style="height: 24px;border-radius:2px;border: 1px solid #ddd">';
            str+='</select>';
            str+='</li>';
            var postdata = {p_dm: "selectYqData"};
            this.initKjData(postdata,function(d){
                var s="";
                 var yqnum =0;
                $.each(d.Table,function(index,data){
                    if(initThat.userqy.length==0||initThat.userqy.indexOf(data.id)>-1){
                        yqnum++;
                        s+='<option value="'+data.code+'"  data-code="'+data.code+'" data-id="'+data.id+'" data-type="'+data.jt+'">'+data.name+'</option>'
                    }
                })
                if(yqnum>1)
                    s='<option value="@novalue"  class="active" data-code="@novalue" data-id="@novalue" data-type="@novalue">全部院区</option>'+s;
                if(s){
                    $("#topdiv").append(str);
                    $("#selyq").append(s);
                    var yqStr = controStr.hasOwnProperty("yqStr")&&controStr.yqStr;
                    $("#selyq").find("option[value='"+yqStr+"']").attr("selected",true);
                }
            });
        }

        if(contro.hasOwnProperty("selCon")&&contro.selCon) {
            var str = "",num=0;
            str += '<li id="seldiv" >';
            str += '<label>对象</label>';
            str += '<select id="selwei" style="height: 24px;border-radius:2px;border: 1px solid #ddd">';
            if(contro.selCon.indexOf("KS")>-1||contro.selCon.length==0){num++;str += '<option value="KS" data-type="KS" class="active">科室</option>';}
            if(contro.selCon.indexOf("MDC")>-1||contro.selCon.length==0){num++;str += '<option selected value="MDC" data-type="MDC">MDC病组</option>';}
            if(contro.selCon.indexOf("DRG")>-1||contro.selCon.length==0){num++;str += '<option value="DRG" data-type="DRG">DRG病组</option>';}
            if(contro.selCon.indexOf("2")>-1||contro.selCon.length==0){num++;str += '<option value="2" data-type="2">手术科室</option>';}
            if(contro.selCon.indexOf("1")>-1||contro.selCon.length==0){num++;str += '<option value="1" data-type="1">非手术科室</option>';}
            if(contro.selCon.indexOf("km01")>-1||contro.selCon.length==0){num++;str += '<option value="km01" data-type="km01">一级科目</option>';}
            if(contro.selCon.indexOf("km02")>-1||contro.selCon.length==0){num++;str += '<option value="km02" data-type="km02">二级科目</option>';}
            if(contro.selCon.indexOf("YS")>-1||contro.selCon.length==0){num++;str += '<option value="YS" data-type="YS">主任医师</option>';}
            if(contro.selCon.indexOf("ZZYS")>-1||contro.selCon.length==0){num++;str += '<option value="ZZYS" data-type="ZZYS">主治医师</option>';}
            if(contro.selCon.indexOf("KZRYS")>-1||contro.selCon.length==0){num++;str += '<option value="KZRYS" data-type="KZRYS">科主任医师</option>';}
            if(contro.selCon.indexOf("ZYYS")>-1||contro.selCon.length==0){num++;str += '<option value="ZYYS" data-type="ZYYS">住院医师</option>';}
            str += '</select>';
            str += '</li>';
            if(num>0){
                $("#topdiv").append(str);
                var weiStr = controStr.hasOwnProperty("weiStr")&&controStr.weiStr;
                $("#selwei").find("option[value='"+weiStr+"']").attr("selected",true);
            }
        }

        if(contro.hasOwnProperty("tbhb")&&contro.tbhb) {
            var str = "";
            str += '<li id="tbhb">';
            str += '<label>选择：</label>';
            str += '<select id="seltbhb" style="height: 24px;border-radius:2px;border: 1px solid #ddd">';
            str += '<option value="tb"  class="active">同比</option>';
            str += '<option value="hb" >环比</option>';
            str += '</select>';
            str += '</li>';
            $("#topdiv").append(str);
            var tbhbStr = controStr.hasOwnProperty("tbhbStr")&&controStr.tbhbStr;
            $("#seltbhb").find("option[value='"+tbhbStr+"']").attr("selected",true);
        }

        if(contro.hasOwnProperty("mdcCon")&&contro.mdcCon) {
            var str = "";
            str += ' <li  id="mdcdiv">';
            str += '<label>MDC</label>';
            str += '<select id="selmdc" class=" easyui-combogrid" name="dept" style="width:100px;">';
            str += '</select>';
            str += '</li>';
            $("#topdiv").append(str);
            var columnsAry=[
                {field:'ck',checkbox:true},
                {field: 'dm', title: '代码', width: 50, align: 'left', halign: 'center'},
                {field: 'mc', title: '名称', width: 180, align: 'left', halign: 'center'}
            ];
            if(contro.mdcCon<=1){
                this.removeAt(columnsAry,0);
            }
            $('#selmdc').combogrid({
                panelWidth: 250,
                panelHeight: 300,
                idField: 'dm',
                textField: 'mc',
                multiple: contro.mdcCon>1,
                // rownumbers:true,//
                columns: [columnsAry]
            });
            $('#selmdc').combogrid('grid').datagrid('enableFilter');
            var postdata = {p_dm: "selectMdcData"};
            this.initKjData(postdata,function (data) {
                initThat.mdcdata=data.Table;
                initThat.mdcdata.unshift({dm:"@novalue",mc:'全部'});
                $('#selmdc').combogrid("grid").datagrid("loadData", initThat.mdcdata);
                var mdcStr = controStr.hasOwnProperty("mdcStr")&&controStr.mdcStr;
                if(mdcStr){
                    $('#selmdc').combogrid("grid").datagrid("selectRecord",mdcStr);
                }else{
                    $('#selmdc').combogrid("grid").datagrid("selectRecord","@novalue");
                }
            });
        }

        if(contro.hasOwnProperty("drgCon")&&contro.drgCon) {
            var str = "";
            str += '<li id="drgdiv">';
            str += '<label>DRGs：</label>';
            str += '<select id="seldrg" class=" easyui-combogrid" name="dept" style="width:100px;"></select>';
            str += '</li>';
            $("#topdiv").append(str);
            var columnsAry=[
                {field:'ck',checkbox:true},
                {field: 'dm', title: '代码', width: 50, align: 'left', halign: 'center'},
                {field: 'mc', title: '名称', width: 180, align: 'left', halign: 'center'}
            ];
            if(contro.drgCon<=1){
                this.removeAt(columnsAry,0);
            }
            $('#seldrg').combogrid({
                panelWidth: 250,
                panelHeight: 300,
                idField: 'dm',
                textField: 'mc',
                multiple: contro.drgCon>1,
                columns: [columnsAry]
            })
            $('#seldrg').combogrid('grid').datagrid('enableFilter');
            var postdata = {p_dm: "selectDrgData"};
            this.initKjData(postdata, function (data) {
                initThat.drgdata=data.Table;
                initThat.drgdata.unshift({dm:"@novalue",mc:'全部'});
                $('#seldrg').combogrid("grid").datagrid("loadData", initThat.drgdata);
                var drgStr = controStr.hasOwnProperty("drgStr")&&controStr.drgStr;
                if(drgStr){
                    $('#seldrg').combogrid("grid").datagrid("selectRecord",drgStr);
                }else {
                    $('#seldrg').combogrid("grid").datagrid("selectRecord", "@novalue");
                }
            });
        }

        if(contro.hasOwnProperty("kmCon")&&contro.kmCon) {
            var str = "";
            str += '<li id="kmdiv">';
            str += '<label>科目：</label>';
            str += '<select id="selkm"  class=" easyui-combogrid" name="dept" style="width:100px;"></select>';
            str += '</li>';
            $("#topdiv").append(str);
            var columnsAry=[
                {field:'ck',checkbox:true},
                {field: 'dm', title: '代码', width: 50, align: 'left', halign: 'center'},
                {field: 'mc', title: '名称', width: 180, align: 'left', halign: 'center'}
            ];
            if(contro.kmCon<=1){
                this.removeAt(columnsAry,0);
            }
            $('#selkm').combogrid({
                panelWidth: 250,
                panelHeight: 300,
                idField: 'dm',
                textField: 'mc',
                multiple: contro.kmCon>1,
                columns: [columnsAry]
            });
            $('#selkm').combogrid('grid').datagrid('enableFilter');
            var postdata = {p_dm: "selectKmData"};
            this.initKjData(postdata,function (data) {
                initThat.kmdata=data.Table;
                initThat.kmdata.unshift({dm:"@novalue",mc:'全部'});
                $('#selkm').combogrid("grid").datagrid("loadData", initThat.kmdata);
                var kmStr = controStr.hasOwnProperty("kmStr")&&controStr.kmStr;
                if(kmStr){
                    $('#selkm').combogrid("grid").datagrid("selectRecord",kmStr);
                }else {
                    $('#selkm').combogrid("grid").datagrid("selectRecord", "@novalue");
                }
            });
        }

        if(contro.hasOwnProperty("ksCon")&&contro.ksCon){
            var str="";
            str+=' <li id="ksdiv">';
            str+='<label>科室</label>';
            str+='<select id="selks"  class=" easyui-combogrid" name="dept" style="width:100px;"></select>';
            str+='</li>';
            $("#topdiv").append(str);
            var columnsAry=[
                {field:'ck',checkbox:true},
                {field: 'code', title: '代码', width: 50, align: 'left', halign: 'center'},
                {field: 'name', title: '名称', width: 180, align: 'left', halign: 'center'}
            ];
            if(contro.ksCon<=1) {
                this.removeAt(columnsAry,0);
        }
            $('#selks').combogrid({
                panelWidth:250,
                panelHeight:300,
                idField:'code',
                textField:'name',
                // rownumbers:true,//
                multiple: contro.ksCon>1,
                columns:[columnsAry]
            });
            $('#selks').combogrid('grid').datagrid('enableFilter');
            var postdata = {p_dm: "selectKsData"};
            this.initKjData(postdata,function(data){
                var userKsdata = [];
                if(initThat.userqyks.length==0){
                    userKsdata = data.Table;
                }
                $.each(initThat.userqyks,function(index,item){
                    if(item.userks.length==0){
                        $.each(data.Table,function(i,d){
                            if(item.yqid== d.yqid) {userKsdata.push(d);}
                        })
                    }else{
                        $.each(item.userks,function(i,d){
                            $.each(data.Table,function(ii,dd) {
                                if(dd.id== d) {userKsdata.push(dd);return true;}
                            });
                        })
                    }
                });
                initThat.ksdata=userKsdata;
                initThat.jtksdata=data.Table1;
                initThat.ksdata.unshift({code:"@novalue",name:'全部'});
                initThat.jtksdata.unshift({code:"@novalue",name:'全部'});
                initThat.loadKsData();
                var ksStr = initThat.controStr.hasOwnProperty("ksStr")&&initThat.controStr.ksStr;
                if(ksStr){
                    $('#selks').combogrid("grid").datagrid("selectRecord",ksStr);
                }else {
                    $('#selks').combogrid("grid").datagrid("selectRecord", "@novalue");
                }
            });
        }
    },
    initKjData:function(postdata,callback,isloading){
        var __this=this;
        if(!isloading)
        {
            $.ajaxSetup({
                async: false
            });
        }
        dLong.getJSON("/commapiV2",postdata,function(data){
            if (data.success) {
                callback&&callback(data);
            }
        });
        if(!isloading)
        {
            $.ajaxSetup({
                async: true
            });
        }
    },
    loadKsData:function(){
        var lx= $("#selyq option:selected").attr("data-type");
        if(lx=="1") {
            $('#selks').combogrid("grid").datagrid("loadData",this.jtksdata);
        }else {
            var data=[];
            var yqid= $("#selyq option:selected").attr("data-id");
            if(yqid&&yqid!="@novalue"){
                $.each(this.ksdata,function(i,d){
                    if(yqid== d.yqid)
                    {
                        data.push(d);
                    }
                })
                data.unshift({code:"@novalue",name:'全部'});
                $('#selks').combogrid("grid").datagrid("loadData", data);
            }else{
                $('#selks').combogrid("grid").datagrid("loadData", this.ksdata);
            }
        }
        $('#selks').combobox('setText', '全部');
        $('#selks').combogrid("grid").datagrid("selectRecord", "@novalue");
    },

    getConditionTime:function(tbhb){
        var cxsj ="";
        var rqkj = $("#rqkj").val();
        var srq = $("#srq").val();
        var erq = $("#erq").val();
        tbhb = tbhb||$("#seltbhb").val();
        var sTime = "",eTime = "",ssTime="",seTime="";
        if(rqkj){
            switch (rqkj){
                case 'y':
                    sTime = srq + "-01-01";
                    eTime = srq + "-12-31";
                    break;
                case 'm':
                    if(new Date(srq)>new Date(erq)){
                        alert("请选择正确时间范围！");
                    }
                    sTime = srq + "-01";
                    eTime = erq +"-"+ (new Date(erq.substring(0,4),erq.substring(5,7),0)).getDate();
                    break;
            }
        }else{
            if(srq&&srq.length==4){sTime = srq + "-01-01";eTime = srq + "-12-31";}
            else if(srq&&srq.length==7){sTime = srq + "-01";eTime = srq +"-"+ (new Date(srq.substring(0,4),srq.substring(5,7),0)).getDate();}
            else if(srq&&srq.length==10){sTime = srq;eTime = srq;}
            if(erq&&erq.length==4){eTime = erq + "-12-31";}
            else if(erq&&erq.length==7){eTime = erq +"-"+ (new Date(erq.substring(0,4),erq.substring(5,7),0)).getDate();}
            else if(erq&&erq.length==10){eTime = erq;}
        }
        cxsj=sTime+";"+eTime;
        if(tbhb){
            if(tbhb=="tb") {
                ssTime = sTime.replace(sTime.substring(0, 4), Number(sTime.substring(0, 4)) - 1);
                seTime = Number(eTime.substring(0, 4)) - 1+"-"+erq.substring(5,7)+"-"+(new Date(Number(eTime.substring(0, 4)) - 1,erq.substring(5,7),0)).getDate();
                cxsj=ssTime+";"+seTime+";"+cxsj;
            }else if(tbhb=="hb") {
                var xcts=this.DateDiff(sTime,eTime);
                var ssTime=this.fun_date(xcts,sTime);
                var seTime=this.fun_date(xcts,eTime);
                seTime = seTime.substring(0,7)+"-"+ (new Date(seTime.substring(0,4),Number(seTime.substring(5,7)),0)).getDate();
                cxsj=ssTime+";"+seTime+";"+cxsj;
            }
        }
        return cxsj+"|";
    },
    getConditionStr:function(weiplan){
       var cxtjStr={
                jtks:"@novalue",
                ks:"@novalue",
                km:"@novalue",
                mdc:"@novalue",
                drg:"@novalue",
                sourceType:"@novalue",
                yq:"@novalue",
                jtkm2:"@novalue",
                cykm2:"@novalue",
                isjtssks:"@novalue",
                iscyssks:"@novalue"
        };
        var yqid=$("#selyq").val();
        var yqtype=$("#selyq option:selected").attr("data-type");
        var kstype=$("#selwei option:selected").attr("data-type");
        if(this.contro.hasOwnProperty("kmCon")&&this.contro.kmCon) {
            var kmAry = $("#selkm").combogrid("grid").datagrid("getSelections");
            var km='';
            $.each(kmAry,function(index,data){
                km=km+data.dm+",";
            });
            if(km.length>0){
                cxtjStr.km = km.substr(0,km.length-1);
            }
        }
        if(this.contro.hasOwnProperty("mdcCon")&&this.contro.mdcCon) {
            var mdcAry = $("#selmdc").combogrid("grid").datagrid("getSelections");

            var mdc='';
            $.each(mdcAry,function(index,data){
                mdc=mdc+data.dm+",";
            });
            if(mdc.length>0){
                cxtjStr.mdc = mdc.substr(0,mdc.length-1);
            }
        }
        if(this.contro.hasOwnProperty("ksCon")&&this.contro.ksCon) {
            var ksAry = $("#selks").combogrid("grid").datagrid("getSelections");
            var ks='';
            $.each(ksAry,function(index,data){
                ks=ks+data.code+",";
            });
            if(yqtype=="1"){
                if(ks.length>0){
                    cxtjStr.jtks = ks.substr(0,ks.length-1);
                }
            }else{
                if(ks.length>0){
                    cxtjStr.ks = ks.substr(0,ks.length-1);
                }
            }
        }
        if(this.contro.hasOwnProperty("drgCon")&&this.contro.drgCon) {
            var drgAry = $("#seldrg").combogrid("grid").datagrid("getSelections");
            var drg='';
            $.each(drgAry,function(index,data){
                drg=drg+data.dm+",";
            });
            if(drg.length>0){
                cxtjStr.drg = drg.substr(0,drg.length-1);
            }
        }


        cxtjStr.yq=yqtype!="1"&&yqtype?yqid:"@novalue";
        cxtjStr.cykm2=yqtype!="1"&&kstype=="km02"?4:"@novalue";
        cxtjStr.iscyssks=yqtype!="1"&&(kstype=="1"||kstype=="2")?(Number(kstype)-1):"@novalue";
        cxtjStr.jtkm2=yqtype=="1"&&kstype=="km02"?4:"@novalue";
        cxtjStr.isjtssks=yqtype=="1"&&(kstype=="1"||kstype=="2")?(Number(kstype)-1):"@novalue";

        if(weiplan||weiplan==0){
            this.weiplan = weiplan;
        }else if(kstype=="YQ"){
            this.weiplan=this.arrs[0];
        } else if(kstype=="MDC") {
            this.weiplan=this.arrs[1];
        } else if(kstype=="DRG") {
            this.weiplan=this.arrs[2];
        } else if(cxtjStr.iscyssks!="@novalue"||(yqtype!="1"&&(kstype=="KS"||!kstype))) {
            this.weiplan=this.arrs[3];
        } else if(cxtjStr.isjtssks!="@novalue"||(yqtype=="1"&&(kstype=="KS"||!kstype))) {
            this.weiplan=this.arrs[4];
        } else if(yqtype=="1"&&kstype=="km01") {
            this.weiplan=this.arrs[5];
        } else if(cxtjStr.jtkm2!="@novalue") {
            this.weiplan=this.arrs[6];
        } else if(yqtype!="1"&&kstype=="km01") {
            this.weiplan=this.arrs[7];
        } else if(cxtjStr.cykm2!="@novalue") {
            this.weiplan=this.arrs[8];
        } else if(kstype=="YS") {
            this.weiplan=this.arrs[9];
        } else if(kstype=="YEAR") {
            this.weiplan=this.arrs[10];
        } else if(kstype=="MONTH") {
            this.weiplan=this.arrs[11];
        } else if(kstype=="ZZYS") {
            this.weiplan=this.arrs[12];
        } else if(kstype=="KZRYS") {
            this.weiplan=this.arrs[13];
        } else if(kstype=="ZYYS") {
            this.weiplan=this.arrs[14];
        }else {
            this.weiplan=this.__weiplan
        }

        var cxtj="";
        for(var key in cxtjStr)
        {
            cxtj+=cxtjStr[key]+"|";
        }
        cxtj+=this.weiplan+"|";
        return {cxtj:cxtj,weiplan:this.weiplan};

    },
    DateDiff:function(sDate1,  sDate2){    //sDate1和sDate2是2006-12-18格式
        var year1 = sDate1.substring(0, 4);
        var year2 = sDate2.substring(0, 4);
        var month1 = sDate1.substring(5, 7);
        var month2 = sDate2.substring(5, 7);
        var len = (year2 - year1) * 12 + (month2 - month1);
        return len+1;
    },
    fun_date:function(a,thistime){
        arr=thistime.split('-');
        var date1 = new Date(arr[0]+'/'+arr[1]+'/01');
        var date2 = new Date(date1);
        date2.setMonth(date1.getMonth()-a);
        var year = date2.getFullYear();
        var month = date2.getMonth()+1;
        if (month < 10) month = "0" + month;
        var time = year +"-"+month+"-01";
        return time;
    },
     getPreMonth:function(date) {
         var year = date.getFullYear(); //获取当前日期的年份
         var month =date.getMonth() + 1; //获取当前日期的月份
         var day = date.getDate(); //获取当前日期的日
         var days = new Date(year, month, 0);
         days = days.getDate(); //获取当前日期中月的天数
         var year2 = year;
         var month2 = parseInt(month) - 1;
         if (month2 == 0) {
             year2 = parseInt(year2) - 1;
             month2 = 12;
         }
         if (month2 < 10) {
             month2 = '0' + month2;
         }
         var t2 = year2 + '-' + month2;
         return t2;
     },
    changeRqkj:function(){
        var val = $("#rqkj").val();
        var date = new Date;
        switch (val){
            case "y":
                $("#srq").attr("onfocus","WdatePicker({el:'srq',startDate:'%y',dateFmt:'yyyy',alwaysUseStartDate:true,maxDate:'%y'})");
                $("#srq").val(date.getFullYear());
                $("#erq").hide();
                break;
            case "m":
                $("#srq").attr("onfocus","WdatePicker({el:'srq',startDate:'%y',dateFmt:'yyyy-MM',alwaysUseStartDate:true,maxDate:'%y'})");
                $("#erq").show();
                var year = date.getFullYear();
                var month = date.getMonth();
                if(month<10){
                    month = "0"+month;
                }
                if(Number(month)==0){
                    $("#srq").val((year-1)+"-12");
                    $("#erq").val((year-1)+"-12");
                }else{
                    $("#srq").val(year+"-"+month);
                    $("#erq").val(year+"-"+month);
                }
                break;
        }
    },
    //绑定easyui表头以及转换数据格式
    getReportEasyUi2:function(weiplan,data,showcoloums,tmc,rowindex,titlebr){
        var returnData={header:[],title:"",data:{total:0,rows:[]}};
        var titles=data.title.column;
        if(typeof titles!="string")
            titles=data.title.column[0].split(",");
        else
            titles=data.title.column.split(",");
        var widths=data.title.width.split(',');
        var aligns=data.title.align.split(',');
        var sorts=(data.title.sort?data.title.sort:data.title.targettype).split(',');
        $.each(showcoloums,function(index,data){
            var head={ field: 'td0',colspan:0,rowspan:0,  title: '', width: 80, align: 'center', halign: 'center' };
            $.each(titles,function(i,d){
                if(i==data)
                {
                    if(tmc)
                        d=tmc[index];
                    head.field="td"+i;
                    var name = d;
                    if(titlebr){
                        name = d.slice(0,4);
                        for(var d_index = 4;d_index<d.length;d_index+=4){
                            name += "<br/>"+d.slice(d_index,d_index+4);
                        }
                    }

                    head.title=name;
                    head.width=Number(widths[i]) ;
                    head.align=aligns[i];
                    head.sortable=true;
                    returnData.header.push(head);
                    return false
                }
            })

        })
        returnData.title=data.title.column;
        var rows=data.rows.row;
        returnData.data.total=rows.length;
        $.each(rows,function(index,data){
            var cell={};
            if(rowindex&&rowindex.indexOf(index)<0)
                return true;
            cell.id=data["@id"];
            $.each(data.cell,function(i,d){
                if(showcoloums.indexOf(i)>=0)
                {
                    if(sorts[i]=="int")
                        d=Number(d);
                    if(i==0&&(weiplan==1||weiplan==2)&&d!='合计'){
                        cell["td"+i]="("+data["@id"]+")"+d;
                    }else{
                        cell["td"+i]=d;
                    }
                }

            })
            returnData.data.rows.push(cell);
        })
        return returnData;
    },
    removeAt: function (target, index) {
        //移除数组中指定位置的元素，返回布尔表示成功与否
        return !!target.splice(index, 1).length
    },
    //获取所有指标
    bindAllTargets:function(parentid,title,defaultsel,mcdiv,hideEvent,topdiv){
        defaultsel=defaultsel||{name:"服务能力",cell:1};
        mcdiv=mcdiv||"selzhibiao";
        var columns=title.split(',');
        var tips="",defaultselText='';
        var s='<div class="top-btn lbtn" id="selzbbtnan"  style="margin-left: 0px;cursor: pointer;"><span class="glyphicon glyphicon-list" style="padding-top: 8px;"></span><span style="margin-left: 6px;" id="mcdivspan"></span></div>';
        tips+='<div class="" id="selzbbtnandiv" >';
        if(topdiv){
            tips+='<div class="mokuai-tow mokuai" style="line-height:30px;">';
            tips+='<span>&nbsp;TOP：</span>';
            tips+='<select id="selsort" style="width: 75px;border:1px solid #ddd;border-radius:3px ">';
            tips+='<option value="desc">倒序</option>';
            tips+='<option value="asc">正序</option>';
            tips+='</select>';
            tips+='<select id="selcount" style="width: 75px;border:1px solid #ddd;border-radius:3px ">';
            tips+='<option value="10">10</option>';
            tips+='<option value="20">20</option>';
            tips+='<option value="30">30</option>';
            tips+='<option value="40">40</option>';
            tips+='<option value="50">50</option>';
            tips+='<option value="">全部</option>';
            tips+='</select>';
            tips+='</div>';
        }
        $.each(this.reportConfig.options,function(index,data){
            tips+=' <div class="mokuai-tow mokuai">';
            tips+='<p>'+data.name+'：</p>';
            tips+='<ul class="lbbtn">';
            $.each(data.cell,function(i,d){
                var j=d;
                if(title.indexOf("#cspan")>0&&d!=1)
                {
                    j=d+(d-1)*3;
                }
                if((defaultsel.name==data.name&&defaultsel.cell==d)||(defaultsel instanceof Array &&defaultsel.indexOf(d)>=0))
                {
                    defaultselText = columns[j];
                    tips+='<li data-id="'+d+'" class="active">'+columns[j]+'</li>';
                }else
                    tips+='<li data-id="'+d+'">'+columns[j]+'</li>';
            })
            tips+='</ul>';
            tips+='</div>';
        })
        s+='</div>';
        $("#"+parentid).html(s);
        var offset= $("#selzbbtnan").offset();
        var height=$("#selzbbtnan").height();
        var width=$("#selzbbtnan").width();

        $("#mcdivspan").text(defaultselText);
        $("#"+mcdiv).text(defaultselText);
        $("#selzbbtnan").click(function(event){
            if($("#shadediv_click").length<=0)
            {
                var s='<div id="shadediv_click" class="hide" style="z-index: 998;width:100%;height:100%;top:0;left:0;position: fixed;"></div>';
                $("body").append(s);
            }
            // $("#selzbbtnandiv").toggleClass('hide');
            $("#shadediv_click").toggleClass('hide');
            layer.tips(tips,this,{tips:[1],time:0, maxWidth:400});

        })
        $('body').delegate('#shadediv_click',"click",function(){
            // $("#selzbbtnandiv").addClass('hide');
            $("#shadediv_click").addClass('hide');
            layer.closeAll("tips");
        })
        if(!hideEvent)
        {
            $('body').delegate("#selzbbtnandiv .lbbtn li","click",function(){
                $('#selzbbtnandiv .lbbtn li').removeClass('active');
                $(this).addClass('active');
                $("#"+mcdiv).text($(this).text());
                $("#mcdivspan").text($(this).text());
            })

        }
    }
}